const formatNumber = n =>{
	n=n.toString()
	return n[1]? n : `0${n}`
}

const formatTime = date =>{
	let year = date.getFullYear()
	let month = date.getMonth() + 1
	let day = date.getDate()
	let hour = date.getHours()
	let minute = date.getMinutes()
	let second = date.getSeconds()
	return `${[year,month,day].map(formatNumber).join('-')} ${[hour, minute,second].map(formatNumber).join(':')}`
}

/**
 * 检查某字段长度是否满足要求
 * @param {Object} field 要检查的对象
 * @param {Number} len 必须满足的长度
 * @param {String} name 该字段中文名称
 * @returns 返回结果是否合法
 */
function checkLen(field,len,name){
	if(field.length >= len){
		return true
	}
	let message = name + "不能少于" + len +"个字符"
	if(field.length == 0){
		message = name+"不能为空"
	}
	uni.showToast({
		title:message,
		icon:'error'
	});
	return false
}

module.exports ={
	formatTime,
	checkLen
}